package org.javaboy;

import java.util.Random;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Supplier;

public class Demo03 {
    public static void main(String[] args) {
        Function<Integer, String> f1 = i -> String.valueOf(i);
        String s = f1.apply(100);
        System.out.println("s = " + s);

        Function<Integer, String> f2 = String::valueOf;
        String s2 = f2.apply(100);
        System.out.println("s2 = " + s2);
        Consumer<String> c1 = str -> System.out.println(str);
        Consumer<String> c2 = System.out::println;
        c2.accept("hello");

        Random random = new Random();
        Supplier<Integer> s3 = () -> random.nextInt();
        System.out.println("s3.get() = " + s3.get());
        Supplier<Integer> s4 = random::nextInt;
        System.out.println("s4.get() = " + s4.get());
        Supplier<User> s5 = () -> new User();
        Supplier<User> s6 = User::new;
        User user = s6.get();

        IntFunction<int[]> f3 = len -> new int[len];
        int[] arr1 = f3.apply(10);
        IntFunction<int[]> f4 = int[]::new;

        String s7 = "hello";
        Function<String, String> c3 = str -> s7 + str;
    }
}
